<?php

namespace app\admin\model;

use think\Model;


class IoCategory extends Model
{


    // 表名
    protected $name = 'io_category';

    // 自动写入时间戳字段
    protected $autoWriteTimestamp = false;

    // 定义时间戳字段名
    protected $createTime = false;
    protected $updateTime = false;
    protected $deleteTime = false;

    // 追加属性
    protected $append = [
    ];

    public function listPidToPName()
    {
        $data = $this->where('pid', 0)->column('name','id');
        $data[0] = '不选择上级';
        return $data;
    }

    public function getTypeAttr($value, $data)
    {
        if ($data['pid'] != 0) {
            return $this->where('id', $data['pid'])->value('type');
        }
        return $value;
    }


}
